import plotly.express as px; import requests; import plotly.io as pio; pio.renderers.default='notebook'
apiurl = 'https://opendata.arcgis.com/datasets/917fc37a709542548cc3be077a786c17_0.geojson'
resp = requests.get(apiurl)
lk_geo = []
for lk in resp.json()["features"]:
AdmUnitId = lk["properties"]["AdmUnitId"]
geometry = lk["geometry"]
defects = [15088, 15002, 8216] # filtering incompatible county polygons to avoid filling contaminations
# todo replace these coordinates with simpler models of another source for instance
if AdmUnitId not in defects:
lk_geo.append({
"type": "Feature",
"geometry": geometry,
"id": AdmUnitId
})
geo = {'type': 'FeatureCollection', 'features': lk_geo}
df = pd.json_normalize(resp.json()["features"])
df = df[(df['properties.AdmUnitId'] > 16)] # only counties starting from index 17
fig = px.choropleth(df, # create map
geojson=geo,
scope="europe",
locations="properties.AdmUnitId",
color="properties.cases7_per_100k",
template="simple_white",
hover_name="properties.GEN",
hover_data=("properties.cases7_per_100k", "properties.cases7_lk", "properties.death7_lk"),
labels={"properties.AdmUnitId": "Landkreis",
"properties.cases7_per_100k": "7-Tage Inzidenz",
"properties.death7_lk": "7-Tage Todesfälle",
"properties.cases7_lk": "7-Tage Neuinfektionen"},
color_continuous_scale=px.colors.sequential.Reds, width=900, height=1000)
fig.update_geos(fitbounds="locations", visible=False)
fig.update_layout(margin={"r": 0, "t": 25, "l": 0, "b": 0})
fig.update_layout(title_text="Seven-day incidence per county as per Robert-Koch-Institute - " + str(df['properties.last_update'][0]))
fig.show()